$(document).ready(function() {
	var VAL ={
        NORMAL : "0000000"  ,
        EVT_USER : $("#userId").text(),
        T_FBPBISTOL : 'FBPBISTOL',
        T_MTPTOOLINS : 'MTPTOOLINS',
        DISABLED_ATTR : {
            'disabled' : true
        },
        ENABLED_ATTR : {
            'disabled' : false
        }
    };

	var domObj = {
		W : $(window),

		$from_date : $("#from_date"),
        $to_date : $("#to_date"),
		$insTypeSel : $("#insTypeSel"),

		buttons : {
			$query_btn : $("#query_btn"),
			$excute_btn : $("#excute_btn"),
			$save_btn : $("#save_btn"),
            $select_btn : $("#select_btn"),
            $add_tool_btn : $("#add_tool_btn"),
            $del_tool_btn : $("#del_tool_btn"),
            $saveToolIns_btn : $("#saveToolIns_btn"),
            $addToolDialog_saveBtn : $("#addToolDialog_saveBtn"),
		},
		
        grids:{
            $insListDiv : $("#insListDiv"),
            $insListGrd : $("#insListGrd"),
            $insListPg : $("#insListPg"),
            $toolListDiv : $("#toolListDiv"),
            $toolListGrd : $("#toolListGrd"),
            $toolListPg : $("#toolListPg"),
            $insItemListDiv : $("#insItemListDiv"),
            $insItemListGrd : $("#insItemListGrd"),
            $insItemListPg : $("#insItemListPg")
        }
	};
	
	var controlsFunc={
	   	resizeFunc : function(){ 
	    	comResize(domObj.W, domObj.grids.$insListDiv, domObj.grids.$insListGrd);
	    	comResize(domObj.W, domObj.grids.$toolListDiv, domObj.grids.$toolListGrd);
	    	comResize(domObj.W, domObj.grids.$insItemListDiv, domObj.grids.$insItemListGrd);
	    },

		//初始化时间
        iniDateTimePicker : function() {
            laydate.render({
                elem: '#from_date',
                type: 'datetime'
            });
            laydate.render({
                elem: '#to_date',
                type: 'datetime'
            });
        },

		//初始化点巡检类型
        iniInsTypeFunc : function(){
            comAddValueByDataCateFnc("#insTypeSel", "PITY", "ext_1", "data_desc", true);
        },

        //初始化厂别
        initFabListFnc : function (){
             comAddValueByDataCateFnc("#fabIdFk","FBID","data_ext","data_desc",true,false);
        },

       //初始化线别
       initLineListFnc : function() {
         comAddValueByDataCateFnc("#lineIdFk", "AREA", "data_ext", "data_desc", true, false);
        },

        //初始化设备
        iniToolSel: function(){
            var fabId =  $.trim($("#fabIdFk").val());
            var lineId =   $.trim($("#lineIdFk").val());
            // var opeId = $.trim($("#opeIdSel").val());
            // var opeVer = '00000';
            var iary2  = {
                fab_id_fk : fabId,
                bay_id :lineId,
                // ope_id_fk : opeId,
                // ope_ver : opeVer
            }
            var inObj2 = {
                trx_id : 'FBPBISTOL',
                action_flg : "Q",
                iary : [iary2]
            };
            var outObj2 = comTrxSubSendPostJson(inObj2);
            if(outObj2.rtn_code === "0000000"){
                SelectDom.initWithSpace($("#toolIdFk"));
                SelectDom.addSelectArr($("#toolIdFk"),outObj2.oary,["tool_id"],["tool_dsc"],"Y",true);
            }
        },

	};
	
	var btnFunc = {
		queryFunc : function(){//查询点巡检任务列表
            var insTypeId = $.trim(domObj.$insTypeSel.val());
            var from_date = $.trim(domObj.$from_date.val());
            var to_date = $.trim(domObj.$to_date.val());
            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'F'        ,
                evt_usr    : VAL.EVT_USER
            };

            if(insTypeId){
                inTrxObj.ins_type = insTypeId;
            }
            if(from_date){
                inTrxObj.from_date = from_date;
            }
            if(to_date){
                inTrxObj.to_date = to_date;
            }

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                setGridInfo(outTrxObj.oaryA,"#insListGrd");
            }
		},

		//执行点巡检任务
		excuteFunc : function(){
            var selRowId = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            if(!selRowId){
                showErrorDialog("","请先选择任务");
                return false;
            }
            var rowData = domObj.grids.$insListGrd.jqGrid("getRowData",selRowId);
            var taskStat = rowData.ins_task_stat;
            if(taskStat !== "WAIT"){
                showErrorDialog("","该任务不是等待状态，不可再次执行！");
                return false;
            }

            var evt_seq_id = rowData.evt_seq_id;
            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'E'        ,
                evt_usr    : VAL.EVT_USER,
                evt_seq_id : evt_seq_id
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                showSuccessDialog("任务开始执行！");
                domObj.grids.$insListGrd.jqGrid('setSelection',selRowId);
                // btnFunc.queryFunc();
                return true;
            }
		},

		//任务结单
		saveFunc : function(){
            var selRowId = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            if(!selRowId){
                showErrorDialog("","请先选择任务");
                return false;
            }
            var rowData = domObj.grids.$insListGrd.jqGrid("getRowData",selRowId);
            var evt_seq_id = rowData.evt_seq_id;
            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'N'        ,
                evt_usr    : VAL.EVT_USER,
                evt_seq_id : evt_seq_id
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                showSuccessDialog("任务已结单");
                btnFunc.queryFunc();
                return true;
            }
		},

		//点检新增设备
		addToolFunc : function(){
            $('#addToolDialog').modal({
                backdrop:true,
                keyboard:false,
                show:false
            });

            $('#addToolDialog').unbind('shown.bs.modal');
            // $("#addToolDialog_cancelBtn").unbind('click');
            // $("#addToolDialog_saveBtn").unbind('click');
            // domObj.buttons.$addToolDialog_saveBtn.click(function () {
            //     btnFunc.bindToolTask();
            // });
            $('#addToolDialog').bind('shown.bs.modal');
            $("#addToolDialogeForm select").select2({
                theme : "bootstrap",
                width : domObj.W.width()* 0.12
            });
            $('#addToolDialog').modal("show");
		},

        //新增点检设备和点检任务绑定 增加点巡检项目
        bindToolTask : function () {
            var selRowId = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            if(!selRowId){
                showErrorDialog("","请先选择任务ID");
                return false;
            }

            var toolIdFk =$("#toolIdFk").val();
            if(!toolIdFk){
                showErrorDialog("","请先选择设备代码！");
                return false;
            }

            var rowData = domObj.grids.$insListGrd.jqGrid("getRowData",selRowId);
            var evtSeqId = rowData.evt_seq_id;
            var insType =  rowData.ins_type;
            var insItemId = rowData.ins_item_id;
            var iaryAlist = new Array();
            var iaryA ={
                tool_id_fk :toolIdFk
            };
            iaryAlist.push(iaryA);

            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'B'        ,
                evt_usr    : VAL.EVT_USER,
                evt_seq_id : evtSeqId,
                ins_type : insType,
                ins_item_id : insItemId,
                iaryA : iaryAlist
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                showSuccessDialog("设备与任务绑定成功");
                $('#addToolDialog').modal("hide");
                btnFunc.findBindTool();//再次查询绑定的任务
                return true;
            }

        },


		//删除点检设备
		deleteToolFunc : function () {
		    //todo show warningdialog

            var selRowId = domObj.grids.$toolListGrd.jqGrid("getGridParam","selrow");
            if(!selRowId){
                showErrorDialog("","请先选择需要删除的设备！");
                return false;
            }

            var rowData = domObj.grids.$toolListGrd.jqGrid("getRowData",selRowId);
            var evt_seq_id = rowData.evt_seq_id;//ret_tool_task主键
            var tool_id_fk = rowData.tool_id_fk;

            var taskRowId  = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            if(!taskRowId){
                showErrorDialog("","请先选择需要接触绑定的任务！");
                return false;
            }
            var rowData2 = domObj.grids.$insListGrd.jqGrid("getRowData",taskRowId);
            var ins_item_id = rowData2.ins_item_id;

            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'M'        ,
                evt_usr    : VAL.EVT_USER,
                evt_seq_id : evt_seq_id,
                ins_item_id : ins_item_id,
                tool_id_fk : tool_id_fk
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                showSuccessDialog("成功删除设备与任务关联");
                btnFunc.findBindTool();
                return true;
            }

        },

		//保存记录
		saveInsRecord : function(){
            var selRowId = domObj.grids.$toolListGrd.jqGrid("getGridParam","selrow");
            var rowData = domObj.grids.$toolListGrd.jqGrid("getRowData",selRowId);
            var tool_id_fk = rowData.tool_id_fk;//ret_tool_task主键

            var taskRowId  = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            var rowData2 = domObj.grids.$insListGrd.jqGrid("getRowData",taskRowId);
            var evt_seq_id = rowData2.evt_seq_id;
            if(rowData2.ins_task_stat !== "INPR"){
                showErrorDialog("", "任务不在进行中，不可进行保存操作！");
                return false;
            }

            var ids = domObj.grids.$insItemListGrd.jqGrid('getGridParam', 'selarrrow');
            if (ids.length < 1) {
                showErrorDialog("", "至少选择一条数据进行保存");
                return false;
            }
            var iaryB =[];
            for (var i = 0; i < ids.length; i++) {
                if ($('#insItemListGrd :text[role="textbox"]').length > 0) {
                    var v = $('#insItemListGrd :text[role="textbox"]').val();
                    $('#insItemListGrd :text[role="textbox"]').parent().attr('title', v);
                    $('#insItemListGrd :text[role="textbox"]').parent().html(v);
                }
                var rowData = domObj.grids.$insItemListGrd.jqGrid("getRowData", ids[i]);
                if (!rowData.data_value) {
                    showErrorDialog("", "第'" + $('#' + ids[i])[0].rowIndex + "'行实际值不能为空");
                    return false;
                }
                /*  if (!ComRegex.isNumber(rowData.data_value)) {
                 showErrorDialog("", "第" + $('#' + ids[i])[0].rowIndex + "行实际值格式不正确！");
                 return false;
                 }*/
                //检查是否超出下规格
                if(rowData['l_spec']){
                    if(!ComRegex.isNumber(rowData.data_value)){
                        showErrorDialog("", "第" + $('#' + ids[i])[0].rowIndex + "行数值格式不正确！");
                        return false;
                    }else if(parseFloat(rowData['data_value'],10) < parseFloat(rowData['l_spec'],10)){
                        showErrorDialog("", "第" + $('#' + ids[i])[0].rowIndex + "行数值小于下规格值"+ parseFloat(rowData['l_spec'],10) + "！");
                        return false;
                    }
                }
                //检查是否超出上规格
                if(rowData['u_spec']){
                    if(!ComRegex.isNumber(rowData.data_value)){
                        showErrorDialog("", "第" + $('#' + ids[i])[0].rowIndex + "行数值格式不正确！");
                        return false;
                    }else if(parseFloat(rowData['u_spec'],10) < parseFloat(rowData['data_value'],10)){
                        showErrorDialog("", "第" + $('#' + ids[i])[0].rowIndex + "行数值大于上规格值"+ parseFloat(rowData['u_spec'],10) + "！");
                        return false;
                    }
                }

                var iary = {
                    data_dsc :   rowData['data_dsc'],
                    l_spec :     rowData['l_spec'],
                    u_spec :     rowData['u_spec'],
                    data_value : rowData['data_value'],
                    ac_ins_note : rowData['ac_ins_note']
                }
                iaryB.push(iary);
            }


            var inObj = {
                trx_id : VAL.T_MTPTOOLINS,
                action_flg : "R",
                evt_usr : VAL.EVT_USER,
                evt_seq_id    : evt_seq_id,
                tool_id_fk : tool_id_fk,
                iaryB  : iaryB,
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                // var length = ids.length;
                // for(var i=0;i<length;i++) {
                //     domObj.grids.$insItemListGrd.jqGrid("delRowData",ids[0]);
                // }
                showSuccessDialog("保存成功");
            }
		},

		//查询任务绑定的设备
        findBindTool : function () {
            var selRowId = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            var rowData = domObj.grids.$insListGrd.jqGrid("getRowData",selRowId);
            var evtSeqId = rowData.evt_seq_id;

            var inTrxObj = {
                trx_id        : VAL.T_MTPTOOLINS ,
                action_flg    : 'H'        ,
                evt_seq_id : evtSeqId
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                setGridInfo(outTrxObj.oaryC, "#toolListGrd");
            }
            $("#insItemListGrd").jqGrid('clearGridData');
        },

		//show出设备需要执行的点巡检项目
        showItemFunc : function () {
            var selRowId = domObj.grids.$toolListGrd.jqGrid("getGridParam","selrow");
            var rowData = domObj.grids.$toolListGrd.jqGrid("getRowData",selRowId);
            var toolIdFk = rowData.tool_id_fk;

            var taskRowId  = domObj.grids.$insListGrd.jqGrid("getGridParam","selrow");
            var rowData2 = domObj.grids.$insListGrd.jqGrid("getRowData",taskRowId);
            var ins_item_id = rowData2.ins_item_id;
            var evt_seq_id = rowData2.evt_seq_id;

            var inTrxObj = {
                trx_id     : VAL.T_MTPTOOLINS ,
                action_flg : 'I'        ,
                evt_usr    : VAL.EVT_USER,
                tool_id_fk : toolIdFk,
                ins_item_id : ins_item_id,
                evt_seq_id : evt_seq_id
            };

            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if( outTrxObj.rtn_code == _NORMAL ) {
                setGridInfo(outTrxObj.oaryB, "#insItemListGrd");
            }
        },


		dialogSaveFunc : function(e){
			var rowData = new Array();
/*			var tool_model = $.trim(domObj.$PMItemDialog_toolRunModeTxt.val());
			if(!tool_model){
				showErrorDialog("","请选择保养设备运行模式！");
				return false;
			}*/
			
			var pm_type = $.trim(domObj.$PMItemDialog_pmTypeSel.val());
			if(!pm_type){
				showErrorDialog("","请选择保养类型！");
				return false;
			}
			
			var data_dsc = $.trim(domObj.$PMItemDialog_dataDscTxt.val());
			if(!data_dsc){
				showErrorDialog("","请输入保养项目名称！");
				return false;
			}
			
			/**
			 * 检查数据格式
			 */
			var u_spec = $.trim(domObj.$PMItemDialog_uSpecTxt.val());
			if(u_spec && !ComRegex.isNumber(u_spec)){
				showErrorDialog("","上规格不是有效的数字");
				return false;
			}
			var l_spec = $.trim(domObj.$PMItemDialog_lSpecTxt.val());
			if(l_spec && !ComRegex.isNumber(l_spec)){
				showErrorDialog("","下规格不是有效的数字");
				return false;
			}
			
			if(u_spec && l_spec && parseFloat(u_spec,10) < parseFloat(l_spec,10)){
				showErrorDialog("","上规格不能小于下规格");
				return false;
			}
			
			var data_typ = $.trim(domObj.$PMItemDialog_dataTypeSel.val());
			if(!data_typ){
				showErrorDialog("","请选择数据类型！");
				return false;
			}
			var pm_note=$.trim(domObj.$PMItemDialog_toolPmNoteTxt.val());
			var data_cnt = $.trim(domObj.$PMItemDialog_sampleQtyTxt.val());
			if(!data_cnt){
				data_cnt = 1;
			}else if(!ComRegex.isInt(data_cnt)){
				showErrorDialog("","样本数量不是有效的数字");
				return false;
			}
			
			rowData.push({
				pm_type_fk  : pm_type,
				data_dsc    : data_dsc,
				u_spec      : u_spec,
				l_spec      : l_spec,
				data_typ    : data_typ,
                pm_note     : pm_note,
				data_cnt    : parseInt(data_cnt)
			});
			if(e.data.action_flg == "U"){
				domObj.grids.$pmItemListGrd.jqGrid("setRowData", e.data.id, rowData[0]);
			}else{
				//新增时检查保养类型和保养项目是否已经存在
				var rowIDs = domObj.grids.$pmItemListGrd.jqGrid('getDataIDs');
				for(var i=0;i<rowIDs.length;i++){
					var rowdata = domObj.grids.$pmItemListGrd.jqGrid("getRowData",rowIDs[i]);
					if(rowdata['pm_type_fk'] == pm_type && rowdata['data_dsc'] == data_dsc){
						showErrorDialog("","此保养类型、保养项目列表中已经存在，请确认！");
						return false;
					}
		        }
				
				var newRowId = getGridNewRowID("#pmItemListGrd");
				domObj.grids.$pmItemListGrd.jqGrid("addRowData", newRowId, rowData[0]);
				controlsFunc.addGridButton();
			}
			$("#PMItemDialog").modal('hide');
		}
	};

  
    function iniGridInfo() {
    	var measureItemListInfoCM = [
     	    {name: 'ins_type'        , index: 'ins_type'       , label: "点巡检类型"        , sortable: false  ,width: 150 },
     	    {name: 'evt_seq_id'        , index: 'evt_seq_id'       , label: "任务ID"        , sortable: false  ,width: 150 ,hidden:true},
            {name: 'ins_task_stat'        , index: 'ins_task_stat'       , label: "任务状态"        , sortable: false  ,width: 150 },
            {name: 'from_date'        , index: 'from_date'       , label: "任务计划开始时间"        , sortable: false  ,width: 150 },
            {name: 'to_date'        , index: 'to_date'       , label: "任务计划结束时间"        , sortable: false  ,width: 150 },
            {name: 'ins_item_id'        , index: 'ins_item_id'       , label: ""        , sortable: false  ,width: 150 ,hidden:true}
     	];
     	domObj.grids.$insListGrd.jqGrid({
     		  url:"",
     	      datatype:"local",
     	      mtype:"POST",
     	      autowidth:true,//宽度根据父元素自适应
              shrinkToFit:false,
              autoScroll: false,
     	      scroll:false,
     	      resizable : true,
     	      loadonce:true,
     	      fixed: true,
     	      viewrecords : true, //显示总记录数
     	      pager : '#insListPg',
     	      rownumbers  :true ,//显示行号
     	      pginput  : false ,
     	      rownumWidth : 20,  //行号列宽度
     	      emptyrecords :true ,
     	      colModel: measureItemListInfoCM,
              onSelectRow : function(id) {
                btnFunc.findBindTool();
            }
     	});
    }

    function iniGridInfo2() {
        var measureItemListInfoCM = [
            {name: 'tool_id_fk'        , index: 'tool_id_fk'       , label: "设备ID"        , sortable: false  ,width: 150 },
            {name: 'tool_dsc'        , index: 'tool_dsc'       , label: "设备描述"        , sortable: false  ,width: 150 },
            {name: 'evt_seq_id'        , index: 'evt_seq_id'       , label: "主键"        , sortable: false  ,width: 150 ,hidden:true}
        ];
        $("#toolListGrd").jqGrid({
            url:"",
            datatype:"local",
            mtype:"POST",
            autowidth:true,//宽度根据父元素自适应
            shrinkToFit:false,
            autoScroll: false,
            scroll:false,
            resizable : true,
            loadonce:true,
            fixed: true,
            viewrecords : true, //显示总记录数
            pager : '#toolListPg',
            rownumbers  :true ,//显示行号
            pginput  : false ,
            rownumWidth : 20,  //行号列宽度
            emptyrecords :true ,
            colModel: measureItemListInfoCM,
            onSelectRow : function(id) {
                btnFunc.showItemFunc();
            }
        });
    }

    function iniGridInfo3() {
        var measureItemListInfoCM = [
            {name: 'data_dsc'        , index: 'data_dsc'       , label: "点巡检项目名称"        , sortable: false  ,width: 150 },
            {name: 'u_spec'        , index: 'u_spec'       , label: "上规格"        , sortable: false  ,width: 150 },
            {name: 'l_spec'        , index: 'l_spec'       , label: "下规格"        , sortable: false  ,width: 150 },
            {name: 'data_value'        , index: 'data_value'       , label: "实际值"        , width: 150 ,editable : true},
            {name: 'ac_ins_note'        , index: 'ac_ins_note'       , label: "备注"        , width: 150 ,editable : true}
        ];
        $("#insItemListGrd").jqGrid({
            url:"",
            datatype:"local",
            mtype:"POST",
            autowidth:true,//宽度根据父元素自适应
            height : 400,
            shrinkToFit:false,
            scroll:false,
            resizable : true,
            loadonce:true,
            fixed: true,
            viewrecords : true, //显示总记录数
            pager : '#insItemListPg',
            rownumbers  :true ,//显示行号
            pginput  : false ,
            rownumWidth : 20,  //行号列宽度
            multiselect : true,
            cellEdit:true,
            cellsubmit:"clientArray",
            emptyrecords :true ,
            colModel: measureItemListInfoCM
        });
    }


    
    /**
     * Ini contorl's data
     */
    var iniContorlData = function(){
    	controlsFunc.resizeFunc();
    	controlsFunc.iniDateTimePicker();
    	controlsFunc.iniInsTypeFunc();
    	controlsFunc.initFabListFnc();
    	controlsFunc.initLineListFnc();
    	controlsFunc.iniToolSel();
    };
    
    /**
     * Bind button click action
     */
    var iniButtonAction = function(){
    	domObj.buttons.$query_btn.click(function(){
    		btnFunc.queryFunc();
    	});

    	domObj.buttons.$add_tool_btn.click(function () {
            btnFunc.addToolFunc();
        });

    	domObj.buttons.$addToolDialog_saveBtn.click(function () {
            btnFunc.bindToolTask();
        });

        domObj.buttons.$del_tool_btn.click(function () {
            btnFunc.deleteToolFunc();
        });

        domObj.buttons.$saveToolIns_btn.click(function () {
            btnFunc.saveInsRecord();
        });

        domObj.buttons.$save_btn.click(function () {
            btnFunc.saveFunc();
        });

        domObj.buttons.$excute_btn.click(function () {
            btnFunc.excuteFunc();
        });

        $("#fabIdFk").on("change",controlsFunc.iniToolSel);
        $("#lineIdFk").on("change",controlsFunc.iniToolSel);
    };
    
    /**
     * Other action bind
     */
    var otherActionBind = function(){
	    domObj.W.resize(function() {
	    	controlsFunc.resizeFunc();
    	});
        
    };

    /**
     * Ini view, data and action bind
     */
    var initializationFunc = function(){
    	iniGridInfo();
    	iniGridInfo2();
    	iniGridInfo3();
    	iniContorlData();
    	iniButtonAction();
    	otherActionBind();
    };
    
    initializationFunc();
    //表格自适应
    function resizeFnc(){
        var offsetBottom, divWidth;
        divWidth = $("#insListDiv").width();
        offsetBottom =  $(window).height() - $("#insListDiv").offset().top;
        $("#insListDiv").height(offsetBottom * 0.95);
        $("#insListDiv").setGridWidth(divWidth * 0.85);
        $("#insListDiv").setGridHeight(offsetBottom * 0.99 - 51);

    };
    resizeFnc();
    $(window).resize(function() {
        resizeFnc();
    });
});